package cn.itlaobing.dao;

import cn.itlaobing.entity.QueryInfo;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Created by Berlin-IOU on 2017/11/9.
 */
public class TrainDao extends BaseDao {
    public QueryInfo findPrice(String trainnum,String goaddress,String toadress) throws SQLException {
        QueryRunner qr=new QueryRunner(getDataSource());
        String sql="SELECT t2.trainNum trainnum,t1.station goaddress,t2.station toaddress,(t2.sitePrice-t1.sitePrice) trainprice FROM (SELECT station,sitePrice FROM tbl_train WHERE station=? AND trainNum=? )t1,(SELECT trainNum,station,sitePrice FROM tbl_train WHERE station=? AND trainNum=?)t2";
        BeanHandler<QueryInfo> beanHandler=new BeanHandler<QueryInfo>(QueryInfo.class);
        QueryInfo queryInfo=qr.query(sql,beanHandler,goaddress,trainnum,toadress,trainnum);
        return  queryInfo;
    }
}
